<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html>
 <head>
    <title>仓库信息管理</title>
    <!-- import css and js -->
	<%@ include file="/common/meta.jsp" %>
	<script src="${ctx}/js/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript">
		var basic_Url="${ctx}/yd/basic/measurementUnit";
		var basic_WUrl="yd/basic/measurementUnit";
		var basic_Title="添加";
		var show_Width=320;
		var show_Hight=150;
		var actionNodeID=null;
		var mid = null;
		function createSearch(){
			init(1,8,'100,100,100,100','20%');

			//第一行的数据
			addCommon(0,0,"lable","单位名称：");
			addCommon(0,1,"txtlike","unitname");
			addCommon(0,2,"lable","单位编码：");
			addCommon(0,3,"txtlike","unitcode");
		}
		
		function searchAP(){
			if(mid != null){
				multipleSearch("#table1",true,"",basic_Url+"/list.do?ID="+mid);
				mid = null;
			}else{
				multipleSearch("#table1",true,"",basic_Url+"/list.do?");
			}
			
		}
		
		
		function gettreeData() 
		 {    
			var manager = null;
			manager = $("#tree1").ligerGetTreeManager(); 
			manager.clear();
	        manager.loadData(null, basic_Url+'/tree.do');
	        manager.collapseAll();
		 }
		
		jQuery(document).ready(function() {
			//创建JQGRID表格
			var grid = $("#table1").ligerGrid({
		        columns: [
		                  { display: '单位编码', name: 'unitcode', width: 150 },
						  { display: '单位名称', name: 'unitname', width: 100 ,
		                	  render:function(item){
		                		  if("0"==item.defaultUnit){
			                		  return "<b>"+item.unitname+"</b>";
		                		  }else{
		                			  return item.unitname;
		                		  }
		                	  }
		                	  
		                  },
		                 
		                  { display: '换算率', name: 'unitconvert', width: 80 },
		                  { display: '是否为基本单位', name: 'defaultUnit', width: 100,
		                	  render:function(item){
		                		  if(item.defaultUnit=="0"){
			                		return "是";  
			                	  } else{
			                		return "否";
			                	  }
		                	  }
		                	 },
		                  { display: '创建人', name: 'dcruser', width: 80 },
		                  { display: '创建时间', name: 'dctime', width: 80,
		                	  render: function (item){
		                		  var cdate=new Date(item.dctime);
		                		  return formatDate(cdate,"yyyy-MM-dd");
		                	  }
		                  },
		                  { display: '描述', name: 'tmpTips', width: 120 ,
		                	  render: function (item){
		                		  if("0"!=item.defaultUnit){
		                			  var tmpTips = "1"+item.unitname+" = <b>"+item.unitconvert+"</b> <基本单位>";
			                		  return tmpTips;
		                		  }else if("0"==item.defaultUnit){
		                			  var tmpTips = "1"+item.unitname+" = <b>"+item.unitconvert+"</b> "+item.unitname;
			                		  return tmpTips;
		                		  }
		                	  }
		                  },
		                  { display: '备注', name: 'remark', width: 120 }
		                      ],  usePager: true,pageSize:15,enabledSort:false,
		                      //url : basic_Url+"/list.do",
		                      width: "100%", height:"92%",pageSizeOptions :[15,25,35], checkbox: true,      
		                      onDblClickRow : function (data, rowindex, rowobj){
		                    	  edititem(data);
		                       },
		                      toolbar: { items: [
												  { text: '增加单位', click: additem, icon: 'add' },
		                                          { text: '修改', click: getSelected, icon: 'modify' },
		                                          { line: true },
		                                          { text: '删除', click: del, img: '../../../js/ligerUI/skins/icons/delete.gif' }
		                                          ]
		                                          }
		                  });
			$("#pageloading").hide();
			
			
			$("#layout1").ligerLayout({ leftWidth: 200,height: '100%',heightDiff:-24,space:4});
			
			 
			
			$("#tree1").ligerTree({  
				 url: basic_Url+'/tree.do',
				 nodeWidth: 500,
				 checkbox: false,
		         slide: false,
		         onClick:function(node){
		        	 actionNodeID = node.data.id;
		        	 multipleSearch("#table1",true,"",basic_Url+"/list.do?ID="+node.data.id);
		         }
		     });
			
			 //添加物料
			 function additem(){
				 if(actionNodeID == null || actionNodeID.length<=0){
					 $.dialog.alert("请选择需要添加的物料!");
					 return false;
				 }
					var url = "yd/basic/measurementUnit/operate/add/"+actionNodeID+".do";
					ShowIframeDialog("operate","添加物料单位",url,320,300);
			 }
			 
			//修改物料
			 function edititem(data){
				if(data.defaultUnit == 0){
					$.dialog.alert("该物料单位为默认单位不能进行修改!");
					return false;
				}else{
					var url = "yd/basic/measurementUnit/operate/edit/"+data.id+".do";
					ShowIframeDialog("operate","修改物料单位",url,320,300);
				}
			}
			//修改物料
			 function getSelected(){
				 var grid = $("#table1").ligerGetGridManager(); 
					var rows = grid.getCheckedRows();
					var data =grid.getSelectedRow();
					if(rows.length==0){
						$.dialog.alert("请选择一行数据!");
						return false;
					}else{
						edititem(data);
					}
			}
			 
		});
	</script>
	
  </head>
<!-- <body onLoad="createSearch()">
   <div id="layout1">-->
    	<!-- <div class="panelBar">
	            <ul class="toolBar">
		           <li><a class="add" onclick="add()"><span>添加</span></a></li>
				   <li><a class="delete" onclick="del()"><span>删除</span></a></li>
               </ul>
          </div> 
         
   			
      </div>
</body> -->
 <body style="padding:10px" onLoad="createSearch()">  
       <div id="pageHeader" class="pageHeader">
               <div class="searchBar" id="multipleSearchDialog">
	                <table class="table" width="100%" id="searchHeader" >  
                        <tbody id="newbody">
                        </tbody>
 	                </table>
                    <div class="subBar">
			             <ul>
				             <li><div class="buttonActive"><div class="buttonContent"><button type="submit" id="btnSearch" onclick="searchAP()">查询</button></div></div></li>
				             <li><a class="button" onclick="clearSearch()"><span>重置</span></a></li>
			             </ul>
	                </div>
               </div>
          </div>
      <div id="layout1">
            <div position="left" title="物料信息">
            <div style="width:100%; height:380px; float:left;overflow:auto;  ">
   				 <ul id="tree1"></ul>
    		</div> 
            </div>
            <div position="center" title="计量单位列表" id="table1">
            
            </div>  
        </div> 
    </body>
</html>